<?php
/**
 *	Version: 2.0
 *	Date: 2014-1-7 00:40
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class plugin_longdu_threadpic{
	function plugin_longdu_gz(){
		global $_G;
	}
}

class threadplugin_longdu_threadpic {
	var $name = null;
	var $iconfile = 'style/picsicon.gif';
	var $buttontext = null;
	
	function threadplugin_longdu_threadpic(){
		global $_G;
		loadcache('plugin');
		$this->name=$_G['cache']['plugin']['longdu_threadpic']['name'];
		$this->iconfile=$_G['cache']['plugin']['longdu_threadpic']['iconfile'] ? $_G['cache']['plugin']['longdu_threadpic']['iconfile'] : 'style/picsicon.gif';
		$this->buttontext=$_G['cache']['plugin']['longdu_threadpic']['buttontext'];
	}
	function newthread($fid) {
		global $editorid,$editormode,$swfconfig,$_G;
		$rdata = C::t('#longdu_threadpic#threadpic_plugin')->fetch_all();
		include_once template('longdu_threadpic:postmod');
		$_G['rdata'] = '['.implode($rdata,',').']';
		//$_G['rdata']=json_encode($rdata);
		return tpl_longdu_threadpic_postpic();
	}
	function newthread_submit($fid) {
		global $_G,$params;
		$params['message'] = dhtmlspecialchars($_GET['atc_content']);
		if (!$_GET['oldatt_desc']) {
			showmessage(lang('plugin/longdu_threadpic','tips01'));
		}
	}
	function newthread_submit_end($fid, $tid) {
		if (is_array($_GET['oldatt_desc']) && count($_GET['oldatt_desc'])) {
			$i = 0;
			foreach ($_GET['oldatt_desc'] as $key=>$val){
				if (!intval($key)) {
					continue;
				}
				$i++;
				C::t('#longdu_threadpic#threadpic_plugin')->qupdata(array('tid'=>$tid,'attdesc'=>dhtmlspecialchars($val),'ox'=>$i),intval($key));
			}
		}
		$threadimage = C::t('#longdu_threadpic#threadpic_plugin')->getthreadimage($tid);
		C::t('forum_threadimage')->delete_by_tid($tid);
		if ($threadimage) {
			C::t('forum_threadimage')->insert(array(
				'tid' => $tid,
				'attachment' => $threadimage['attachment'],
				'remote' => $threadimage['remote'],
			));
			C::t('forum_thread')->update($tid, array('cover' => 1));
		}else{
			C::t('forum_thread')->update($tid, array('cover' => 0));
		}
	}
	function editpost($fid, $tid) {
		global $editorid,$editormode,$swfconfig,$_G,$postinfo;
		$rdata = C::t('#longdu_threadpic#threadpic_plugin')->fetch_all($_G['tid']);
		include_once template('longdu_threadpic:postmod');
		$_G['rdata'] = '['.implode($rdata,',').']';
		return tpl_longdu_threadpic_postpic();
	}
	function editpost_submit($fid, $tid) {
		global $_G,$message;
		$message = dhtmlspecialchars($_GET['atc_content']);
		if (!$_GET['oldatt_desc']) {
			showmessage(lang('plugin/longdu_threadpic','tips01'));
		}
	}
	function editpost_submit_end($fid, $tid) {
		
		if (is_array($_GET['oldatt_desc']) && count($_GET['oldatt_desc'])) {
			$i = 0;
			foreach ($_GET['oldatt_desc'] as $key=>$val){
				if (!intval($key)) {
					continue;
				}
				$i++;
				C::t('#longdu_threadpic#threadpic_plugin')->qupdata(array('tid'=>$tid,'attdesc'=>dhtmlspecialchars($val),'ox'=>$i),intval($key));
			}
		}
		$threadimage = C::t('#longdu_threadpic#threadpic_plugin')->getthreadimage($tid);
		C::t('forum_threadimage')->delete_by_tid($tid);
		if ($threadimage) {
			C::t('forum_threadimage')->insert(array(
				'tid' => $tid,
				'attachment' => $threadimage['attachment'],
				'remote' => $threadimage['remote'],
			));
			C::t('forum_thread')->update($tid, array('cover' => 1));
		}else{
			C::t('forum_thread')->update($tid, array('cover' => 0));
		}
	}
	function viewthread($tid) {
		global $_G,$thread,$postlist,$thread;
		$tid=$_G['tid'];
		foreach ($postlist as $key=>$val){
			if ($val['first']) {
				$thread['message'] = $val['message'];
				$postlist[$key]['message']='';
				break;
			}
		}
		$rdata = C::t('#longdu_threadpic#threadpic_plugin')->fetch_all($_G['tid'],true);
		include_once template('longdu_threadpic:postmod');
		return tpl_longdu_threadpic_viewpic($rdata);
	}
} 

?>